import { Controller, Delete, Get, Post, Put, Body, Param, ParseIntPipe } from '@nestjs/common';
import { DeleteResult, UpdateResult } from 'typeorm';
import { RoleEntity } from './../../entities/role.entity';
import { RoleService } from './../../services/role/role.service';

@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post()
  async createRole(@Body() data: RoleEntity): Promise<RoleEntity> {
    return await this.roleService.createRole(data);
  }

  @Delete(':id')
  async deleteRoleById(@Param('id', new ParseIntPipe()) id: number): Promise<DeleteResult> {
    return await this.roleService.deleteRoleById(id);
  }

  @Put(':id')
  async updateRoleById(
    @Param('id', new ParseIntPipe()) id: number,
    @Body() data: RoleEntity
  ): Promise<UpdateResult> {
    return await this.roleService.updateRoleById(id, data);
  }

  @Get()
  async findRoleList(): Promise<RoleEntity[]> {
    return await this.roleService.findRoleList();
  }

  @Get(':id')
  async findRoleById(@Param('id', new ParseIntPipe()) id: number): Promise<RoleEntity> {
    return await this.roleService.findRoleById(id);
  }
}
